package com.htgd.gardenexpo.controller;


import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConAchievement;
import com.htgd.gardenexpo.entity.GeConHealthy;
import com.htgd.gardenexpo.entity.GeConTheaterMovie;
import com.htgd.gardenexpo.page.AchievementQuery;
import com.htgd.gardenexpo.page.MovieQuery;
import com.htgd.gardenexpo.service.GeConAchievementService;
import com.htgd.gardenexpo.vo.GeConAchievementVO;
import com.htgd.gardenexpo.vo.GeConHealthyVO;
import com.htgd.gardenexpo.vo.GeConTheaterMovieVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 成就管理 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-20
 */
@RestController
@RequestMapping("/api/achievement")
@Api(tags = "成就管理")
public class GeConAchievementController {

    @Autowired
    private GeConAchievementService geConAchievementService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public CommonResult add(@RequestBody GeConAchievement geConAchievement) {
        geConAchievement.setStatus(4);
        geConAchievement.setDelFlag(0);
        geConAchievementService.save(geConAchievement);
        return CommonResult.success("添加成功");
    }

    @PostMapping(value = "/edit")
    @ApiOperation("编辑")
    public CommonResult edit(@RequestBody GeConAchievement geConAchievement) {
        geConAchievementService.updateById(geConAchievement);
        return CommonResult.success("修改成功");
    }

    @DeleteMapping(value = "/delete")
    @ApiOperation("删除")
    public CommonResult delete(String id) {
        GeConAchievement geConAchievement = new GeConAchievement();
        geConAchievement.setId(id);
        geConAchievement.setDelFlag(1);
        geConAchievementService.updateById(geConAchievement);
        return CommonResult.success("删除成功");
    }

    @GetMapping(value = "/list")
    @ApiOperation("查询")
    public CommonResult<List<GeConAchievementVO>> list(AchievementQuery achievementQuery) {
        PageInfo<GeConAchievementVO> list = geConAchievementService.pageList(achievementQuery);
        return CommonResult.success(String.valueOf(list.getTotal()),list.getList());
    }

    @GetMapping(value = "/details")
    @ApiOperation("详情")
    public CommonResult<GeConAchievementVO> details(String id) {
        GeConAchievementVO geConAchievementVO = new GeConAchievementVO();
        GeConAchievement geConAchievement = geConAchievementService.getById(id);
        BeanUtils.copyProperties(geConAchievement,geConAchievementVO);
        return CommonResult.success("查询成功",geConAchievementVO);
    }

    @PostMapping(value = "/review")
    @ApiOperation("审核")
    public CommonResult review(@RequestBody GeConAchievement geConAchievement) {
        geConAchievementService.updateById(geConAchievement);
        return CommonResult.success("成功");
    }

}
